package manager

import (
	"encoding/json"
)

const (
	REST_SUCCESS = 0
	REST_FAILED  = 1
)

type ACBaseResponse struct {
	Code     int         `json:"code"`
	ErrorMsg string      `json:"errorMsg"`
	Data     interface{} `json:"data"`
}

func (this *ACBaseResponse) MapDataToArray() []interface{} {
	return this.Data.([]interface{})
}

func (this *ACBaseResponse) MapDataToObj(returnObj interface{}) interface{} {
	if err := json.Unmarshal(this.Data.([]byte), &returnObj); err != nil {
		return returnObj
	}
	return nil
}

func (this *ACBaseResponse) MapToMap() map[string]interface{} {
	if this.Data == nil {
		return nil
	} else {
		return this.Data.(map[string]interface{})
	}
}

func (this *ACBaseResponse) MapDataToInt() int {
	if this.Data == nil {
		return -1
	} else {
		return this.Data.(int)
	}
}

func (this *ACBaseResponse) MapDataToBool() bool {
	if this.Data == nil {
		return false
	} else {
		return this.Data.(bool)
	}
}

func (this *ACBaseResponse) MapDataToString() string {
	if this.Data == nil {
		return ""
	} else {
		return this.Data.(string)
	}
}
